package com.wenchao.jetpackdemo.navigation

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.fragment.NavHostFragment
import com.wenchao.jetpackdemo.R
import com.wenchao.jetpackdemo.databinding.ActivityNavigationSimpleBinding

class NavigationSimpleActivity : AppCompatActivity() {

    private lateinit var binding: ActivityNavigationSimpleBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityNavigationSimpleBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.frag_nav_simple) as NavHostFragment?
        val navSimple = navHostFragment!!.navController.navInflater.inflate(R.navigation.nav_simple)
        navHostFragment.navController.graph = navSimple
    }

    override fun onSupportNavigateUp(): Boolean {
        return Navigation.findNavController(this, R.id.frag_nav_simple).navigateUp()
    }

}